import 'package:boss/color_constant.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/image/base_image.dart';
import 'package:boss/ui/widget/picker/imagePicker/image_picker.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

class PackageImage extends StatefulWidget {
  final String imageUrl;
  final ValueChanged<String> onUploaded;

  const PackageImage({
    Key key,
    this.imageUrl,
    this.onUploaded,
  }) : super(key: key);

  @override
  _PackageImageState createState() => _PackageImageState();
}

class _PackageImageState extends State<PackageImage> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () async {
        var image = await ImagePicker.pickImage(context);
        if (image != null) {
          var imageUrl = await UploadUtil.uploadImage(image);
          if (imageUrl != null && widget.onUploaded != null) {
            widget.onUploaded(imageUrl);
          }
        }
      },
      child: Container(
        height: 260.w,
        color: ColorConstant.f7f7,
        alignment: Alignment.center,
        child: widget.imageUrl == null
            ? Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  BaseImage(
                    'assets/image/package_image_icon.png',
                    width: 90.w,
                    height: 70.w,
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 20.w),
                    child: Text(
                      '上传套餐图',
                      style: TextStyleConstant().normal_4_28,
                    ),
                  ),
                ],
              )
            : BaseImage(
                widget.imageUrl,
                width: double.infinity,
                height: 260.w,
                fit: BoxFit.fill,
              ),
      ),
    );
  }
}
